home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
mouse.exe
/
MOUSESUB.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-06-03
|
15KB
|
378 lines
{ This is the MOUSESUB.PAS include file for the MOUSE.PAS unit. }
{ It contains various special mouse routines used by the Mouse unit. }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{Special inline functions used by the Mouse unit}
{---------------------------------------------------------------------------}
{ an inline function to limit an integer between min and max values}
function IntLimit(Val,Min,Max:Integer):Integer;
Inline(
$58 { pop AX}
/$5B { pop BX}
/$59 { pop CX}
/$39/$C8 { cmp AX,CX}
/$7C/$08 { jl done}
/$89/$D8 { mov AX,BX}
/$39/$C8 { cmp AX,CX}
/$7F/$02 { jg done}
/$89/$C8); { mov AX,CX}
{done:}
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ The following procedures use the mouse functions to provide }
{ a higher level of control over the mouse }
{---------------------------------------------------------------------------}
{ Normalizes a mouse X position to standard position info }
function GetMx(X:Integer):Integer;
begin
case CrtMode of
0,1 : begin
if MaxCrtX < 64 then
MouseTemp := (X shr 1) div MouseTextWidth {320x200 text}
else
MouseTemp := X div MouseTextWidth; {???x??? text}
end;
2,3 : MouseTemp := X div MouseTextWidth; {640x200 text}
4,5 : begin
if HercGraphMouse then
MouseTemp := X {720x348 herc graphics}
else
MouseTemp := X shr 1; {320x200 graphics}
end;
6 : MouseTemp := X; {640x200 graphics}
7 : MouseTemp := X div MouseTextWidth; {640x??? text}
$D,$13 : MouseTemp := X shr 1; {320x200 graphics}
else
MouseTemp := X; {640x??? graphics}
end;
if ZeroMouse then
GetMx := MouseTemp {zero based mouse positioning}
else
GetMx := succ(MouseTemp); {mouse positioning starts with one}
end;
{---------------------------------------------------------------------------}
{ Normalizes a mouse Y position to standard position info }
function GetMy(Y:Integer):Integer;
begin
if TextMouse then
MouseTemp := Y div MouseTextHeight {convert position for text modes}
else
MouseTemp := Y; {no conversion needed for graphics}
if ZeroMouse then
GetMy := MouseTemp {zero based mouse positioning}
else
GetMy := succ(MouseTemp); {mouse positioning starts with one}
end;
{---------------------------------------------------------------------------}
{ converts a standard X position to a mouse X position }
function PutMx(X:Integer):Integer;
begin
if ZeroMouse then
MouseTemp := X {zero based mouse positioning}
else
MouseTemp := pred(X); {mouse positioning starts with one}
if MouseTemp < 0 then {clip value to zero}
MouseTemp := 0;
case CrtMode of
0,1 : begin
if MaxCrtX < 64 then
PutMx := (MouseTemp * MouseTextWidth) shl 1 {320x200 text}
else
PutMx := MouseTemp * MouseTextWidth; {???x??? text}
end;
2,3 : PutMx := MouseTemp * MouseTextWidth; {640x200 text}
4,5 : begin
if HercGraphMouse then
PutMx := MouseTemp {720x348 herc graphics}
else
PutMx := MouseTemp shl 1; {320x200 graphics}
end;
6 : PutMx := MouseTemp; {640x200 graphics}
7 : PutMx := MouseTemp * MouseTextWidth; {640x??? text}
$D,$13 : PutMx := MouseTemp shl 1; {320x200 graphics}
else
PutMx := MouseTemp; {640x??? graphics}
end;
end;
{---------------------------------------------------------------------------}
{ converts a standard Y position to a mouse Y position }
function PutMy(Y:Integer):Integer;
begin
if ZeroMouse then
MouseTemp := Y {zero based mouse positioning}
else
MouseTemp := pred(Y); {mouse positioning starts with one}
if MouseTemp < 0 then {clip value to zero}
MouseTemp := 0;
if TextMouse then
PutMy := MouseTemp * MouseTextHeight {convert position for text modes}
else
PutMy := MouseTemp; {no conversion needed for graphics}
end;
{---------------------------------------------------------------------------}
{ This procedure is not a standard mouse function. It is however needed to }
{ work with the Hercules graphics display. When you use the Hercules }
{ graphics display you must call this with the proper display page after }
{ you call InitGraph, but before you call InitMouse. InitGraph needs CrtMode}
{ to be at 7 to detect the Herc display, but the Mouse needs it at 5 or 6 }
{ to detect when the Herc card is in graphs mode. (The Herc card has no }
{ provision for telling the system that it is graphics mode.) }
{ Note: Be sure to call this procedure with a Pg of -1 if you turn graphics }
{ off or anytime before you call InitGraph or DetectGraph. The Mouse unit }
{ contains an Exit procedure that calls SetHercMouse with a value of -1 if }
{ a Hercules graph mode was selected so that the CrtMode byte will be }
{ properly restored on exit from the program. }
procedure SetHercMouse(Pg:Integer);
begin
Case Pg of
0 : begin
CrtMode := 6; { put mouse on Hercules graphics display Pg 0 }
HercGraphMouse := true;
end;
1 : begin
CrtMode := 5; { put mouse on Hercules graphics display Pg 1 }
HercGraphMouse := true;
end;
else
begin
CrtMode := 7; { indicate that Hercules display is in text mode }
HercGraphMouse := false;
end;
end;
end;
{---------------------------------------------------------------------------}
{ Check if a mouse point is currently in the specified area}
{ returns true if it is, false if not}
{ Recommended calling method: }
{ If MousePointIn(GetMx(Mx),GetMy(My),x1,y1,x2,y2) then DoSomething;}
function MousePointIn(Mx,My, x1,y1,x2,y2:Integer):Boolean;
begin
if (Mx >= x1) and
(Mx <= x2) and {check if in the box area}
(My >= y1) and
(My <= y2) then
MousePointIn := true {<-- return true if it is}
else
MousePointIn := false; {<-- return false if it is not}
end;
{---------------------------------------------------------------------------}
function MouseClick:Boolean; {has the mouse been clicked recently?}
begin
MouseClick := MouseClicked; {get a copy of the click status}
MouseClicked := false; {then clear the status}
end;
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ the following are misc subroutines used by the Mouse unit }
{---------------------------------------------------------------------------}
{ This is called by InitMouse to initialize the mouse mode flags}
{ Note: if you are using a Hercules display card in graphics mode,}
{ you must call the SetHercMouse() procedure before calling InitMouse}
procedure InitMouseMode;
begin
MouseAreaX1 := 0; {initialize mouse bounded area}
MouseAreaY1 := 0; {assume defaults to start}
MouseAreaX2 := 639;
MouseAreaY2 := 199;
MouseTextWidth := 8; {BIOS characters are always 8 wide}
MouseTextHeight := 8; {def